package com.ynrcc.efiles;

import java.io.File;

import com.eova.config.EovaConfig;
import com.eova.config.EovaInit;
import com.jfinal.core.Controller;
import com.ynrcc.model.Attachment;
import com.ynrcc.model.FileInfo;

public class EfilesController extends Controller{
	public void file() throws Exception{
		int id = getParaToInt(0);
		FileInfo file = FileInfo.dao.findById(id);
		setAttr("file_info",file);
		
		render("/efiles/file/file.html");
	}
	
	public void detail() throws Exception{
		int id = getParaToInt(0);
		FileInfo file = FileInfo.dao.findById(id);
		System.out.println(file.get("NAME"));
		setAttr("file_info",file);
		
		render("/efiles/file/detail.html");
	}
	
	public void download() throws Exception{
		int id = getParaToInt(0);
		System.out.println(id);
		Attachment attr = Attachment.dao.findById(id);
		EovaInit.initConfig();
		File file = new File(EovaConfig.props.get("filedb") + attr.getPath() + attr.getName());
		System.out.println(file);
		
		renderFile(file);
	}
}
